package com.album.task;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;

import com.album.http.HttpRequest;
import com.album.utils.CommonUtil;
import com.album.utils.Config;
import com.album.utils.MyLog;

public class DownImageTask extends Task{
	public String TAG = "DelPicinfoTask";
	private Context ctx;
	private ICallBack callBack;
	private String username; 
	private List<String> filenameList;
	
	public DownImageTask(Context ctx,String username,List<String> filenameList,ICallBack resTask){
		this.ctx = ctx;
		this.callBack = resTask;
		this.username = username;
		this.filenameList = filenameList;
	}
	@Override
	public String setRequest(){
		//test
//		List<String> test =  new ArrayList<String>();
//		test.add("tmp/18926128667@189.cn/20110823125438_46272.jpg");
//		test.add("tmp/18926128667@189.cn/20110823125558_73824.jpg");
//		test.add("tmp/18926128667@189.cn/20110823125640_40564.jpg");
//		test.add("tmp/18926128667@189.cn/20110823125704_65404.jpg");
		//test
		for (String filename : filenameList) {
			if (filename != null && filename.length() != 0) {
				filename = filename.substring(filename.lastIndexOf("/") + 1);
			}
			MyLog.info(getClass(), "downImage filename:"+filename);
			String strUrl =Config.TyDownHttp+username+"/"+filename;
			MyLog.info(getClass(), "downImage trl:"+strUrl);
			try {
				Bitmap bm= CommonUtil.loadBitMap(ctx,strUrl);
				if(bm != null)
				callBack.CallBack(filename,bm);
			}catch (OutOfMemoryError ex){ continue;}
		}
		return null;
	}
	@Override
	public void doTask(Task thread){
		Thread t = new Thread(thread);
		t.start();
	}
	@Override
	public void run() {
		//返回数据
		try {
			setRequest();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

